﻿@{
    ViewBag.Title = "Index";
}
<div class="layui-form-item">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" id="Code" placeholder="园区名称" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="DeptName" placeholder="所属公司" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:80px;">
            <input type="text" id="DeptName" placeholder="省份" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:80px;">
            <input type="text" id="DeptName" placeholder="城市" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:80px;">
            <input type="text" id="DeptName" placeholder="区县" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="DeptName" placeholder="园区地址" autocomplete="off" class="layui-input">
        </div>
        @*<div class="layui-input-inline">
            <input type="text" id="DeptName" placeholder="证照信息" autocomplete="off" class="layui-input">
        </div>*@
    </div>
    <div class="layui-inline">
        <a class="layui-btn" id="btnSearch">搜索</a>
    </div>
</div>
<table id="table" class="layui-table" lay-filter="table"></table>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        @Html.LayuiButton("add", "新增园区", "layui-btn layui-btn-sm", "/Resource/Park/Add")
        @Html.LayuiButton("edit", "编辑园区", "layui-btn layui-btn-sm", "/Resource/Park/Edit")
        @*@Html.LayuiButton("delete", "删除", "layui-btn layui-btn-sm", "/Resource/Park/Index")*@
    </div>
</script>
<script type="text/html" id="rowbar">
    <a class="layui-btn layui-btn-xs" lay-event="show3d">3D模型</a>
    @*@Html.LayuiButton("edit", "修改", "layui-btn layui-btn-primary layui-btn-xs", "/Resource/Park/Index")
    @Html.LayuiButton("del", "删除", "layui-btn layui-btn-danger layui-btn-xs", "/Resource/Park/Index")*@
</script>
<script>
    layui.use(['table', 'layer'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        //查询
        function getWhere() {
            var where = { Code: $("#Code").val() };
            return where;
        }
        layui.tableReload = function () {
            table.reload("table", {
                where: getWhere(),
                page: { curr: 1 }
            });
        }
        $("#btnSearch").click(function () {
            layui.tableReload();
        })
        // 渲染表格
        table.render({
            id: "table",
            elem: '#table',
            method: "post",
            url: 'List',
            cellMinWidth: 80,
            toolbar: "#toolbar",
            cols: [
                [
                    { type: 'checkbox' },
                    { field: 'Code', title: '园区名称' },
                    { field: 'DeptName', title: '所属公司' },
                    { field: 'ProvinceName', title: '省份' },
                    { field: 'CityName', title: '城市' },
                    { field: 'CountyName', title: '区县' },
                    { field: 'Address', title: '园区地址' },
                    //{ field: 'ZZXX', title: '证照信息' },
                    //{ field: 'TDXX', title: '土地信息' },
                    //{ field: 'SCXX', title: '生产信息' },
                    //{ field: 'YQAB', title: '园区安保' },
                    //{ field: 'PTSS', title: '配套设施' },
                    //{ field: 'SHPL', title: '适合品类' },
                    { field: 'Area', title: '园区面积' },
                    //{ field: 'Longitude', title: '经度' },
                    //{ field: 'Latitude', title: '纬度' },
                    { field: 'CreateDate', title: '创建日期' },
                    { fixed: 'right', title: '操作', align: 'center', toolbar: '#rowbar' }
                ]
            ],
            done: function (res, curr, count) { //res 即为原始返回的数据
                //console.log(res);
            },
            page: { limit: 20 }
        });
        
        //监听头部事件
        table.on('toolbar(table)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: '新增园区',
                        maxmin: true,
                        area: ['400px', '525px'],
                        content: 'Add',
                        end: function () {
                            layui.tableReload();
                        },
                        success: function (layero,index) {
                            layer.iframeAuto(index);
                        }
                    });
                    break;
                case 'edit':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.open({
                            type: 2,
                            title: '编辑园区',
                            maxmin: true,
                            area: ['400px', '525px'],
                            content: 'Edit?id=' + data[0].ID,
                            end: function () {
                                layui.tableReload();
                            },
                            success: function (layero, index) {
                                layer.iframeAuto(index);
                            }
                        });
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        $.ajax({
                            url: 'Delete',
                            data: { id: data[0].ID },
                            success: function (res) {
                                layer.alert(res.msg, function () {
                                    layui.tableReload();
                                })
                            }
                        });
                    }
                    break;
            };
        });
        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'show3d') {
                if (data.Url3D) {
                    layer.open({
                        type: 2,
                        title: '园区三维模型',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '/Resource/Show3D/ShowRent?id=' + data.ID
                    });
                }
                else
                    layer.msg("尚未配置3D模型链接");
            }
        });
    });
</script>
